package com.xiaoc.bulldozer.controller;

import com.xc.framework.common.page.PageDto;
import com.xiaoc.bulldozer.common.dto.WeixinUserDto;
import com.xiaoc.bulldozer.common.dto.WeixinUserQueryDto;
import com.xiaoc.bulldozer.facade.WeixinUserFacade;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * describe:
 *
 * @author lihuancheng
 * @date 2018/9/12
 */
@Controller
@RequestMapping(value = "/weixin")
public class WeixinUserController extends AdminBaseController {

    @Resource(name = "weixinUserFacade")
    private WeixinUserFacade weixinUserFacade;

    @GetMapping(value = "/list")
    public ModelAndView list(WeixinUserQueryDto weixinUserQueryDto) {

        weixinUserQueryDto.setPhoneNumber(StringUtils.trimToNull(weixinUserQueryDto.getPhoneNumber()));
        Map<String, Object> params = new HashMap<>();
        int count = weixinUserFacade.getWeixinUserCount(weixinUserQueryDto);

        if (count > 0) {
            List<WeixinUserDto> weixinUserDtoList = weixinUserFacade.getWeixinUserList(weixinUserQueryDto);
            params.put("userList", weixinUserDtoList);
        }

        params.put("pageDto", new PageDto(weixinUserQueryDto.getPage(), count, PageDto.PAGE_SIZE));
        return renderHtml("/weixinUser/list.html", params);

    }
}
